package jianzhi

func getKthFromEnd(head *ListNode, k int) *ListNode {

	if head == nil {
		return nil
	}

	len := 0

	for temp := head; temp != nil; temp = temp.Next {
		len++
	}

	if k > len {
		return head
	}

	temp := head

	for ; temp != nil; temp = temp.Next {

		if len == k {
			return temp
		}
		len--
	}
	return temp

}
